#ifndef LED_H
#define LED_H

#include <Arduino.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "../shared_values.h"

// LED状态枚举
enum LedState {
    LED_OFF,
    LED_BLINK,
};

uint32_t last_time = 0;
uint32_t led_period = 1000; // 默认周期为1秒
LedState current_state = LED_OFF;

// 初始化LED
void led_init();

// 设置LED状态
void set_led_state(LedState state);

// 设置LED周期（单位：毫秒）
void set_led_period(uint32_t period);

void led_looper(){
    if (current_state == LED_BLINK) {
        if (millis() - last_time >= led_period) {
            digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // 切换LED状态
            last_time = millis();
        }
    } else {
        digitalWrite(LED_PIN, HIGH); // 关闭LED
    }
}

void led_init() {
    pinMode(LED_PIN, OUTPUT);
    current_state = LED_BLINK; // 默认状态为闪烁
}

void set_led_state(LedState state) {
    current_state = state;
}

void set_led_period(uint32_t period) {
    led_period = period;
}


#endif